package com.weayer.controller;

import com.weayer.dto.ResponseResult;
import com.weayer.request.VerificationCodeDTO;
import com.weayer.service.VerificationCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: Api服务 - 司机 - 验证码controller
 * @author: Weayer
 **/
@RestController
public class VerificationCodeController {
    @Autowired
    private VerificationCodeService verificationCodeService;

    /**
     * @Description: 验证码生成
     * @Param: [verificationCodeDTO]
     * @return: com.weayer.dto.ResponseResult
     **/
    @GetMapping("/verification-code")
    public ResponseResult verificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
        String driverPhone = verificationCodeDTO.getDriverPhone();
        return verificationCodeService.generatorCode(driverPhone);
    }

    /**
     * @Description: 验证码校验
     * @Param: [verificationCodeDTO]
     * @return: com.weayer.dto.ResponseResult
     **/
    @PostMapping("/verification-code-check")
    public ResponseResult checkVerificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
        String driverPhone = verificationCodeDTO.getDriverPhone();   // 手机号
        String verificationCode = verificationCodeDTO.getVerificationCode(); // 验证码
        return verificationCodeService.checkCode(driverPhone, verificationCode);
    }
}
